package org.smr.ministore.controller;

import javax.annotation.Resource;

import org.blade.msg.DataMessage;
import org.blade.msg.Message;
import org.blade.utils.Pager;
import org.smr.ministore.entities.GoodsTypeOrgan;
import org.smr.ministore.entities.vo.GoodsTypeOrganQuery;
import org.smr.ministore.service.GoodsTypeOrganService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;


@Controller("GoodsTypeOrganController")
public class GoodsTypeOrganController {

	@Resource
	private GoodsTypeOrganService service;
	
	/**
	 * 保存编辑后的GoodsTypeOrgan信息
	 * @param GoodsTypeOrgan
	 * @return
	 */
	@ResponseBody
	@RequestMapping(method = RequestMethod.PATCH, value = "/GoodsTypeOrgan/edit")
	public Message modify(@RequestBody GoodsTypeOrgan GoodsTypeOrgan){
		Message msg = new Message();
		
		if(null == GoodsTypeOrgan.getId()){
			msg.setStatus(service.save(GoodsTypeOrgan));
		}else{
			msg.setStatus(service.updateById(GoodsTypeOrgan));
		}
		return msg;
	}
	
	/**
	* 跳转到列表查询GoodsTypeOrgan
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET, value = "/GoodsTypeOrgan/list-page")
	public String toList(){
		return "/GoodsTypeOrgan/GoodsTypeOrgan-list";
	}

	/**
	*  根据id查询GoodsTypeOrgan
	* @return
	*/
	@ResponseBody
	@RequestMapping(method = RequestMethod.GET, value = "/GoodsTypeOrgan")
	public GoodsTypeOrgan get( Long id ){
		return service.queryById(id);
	}


    /**
	 * 分页查询GoodsTypeOrgan信息
	 * @param GoodsTypeOrgan
	 * @param pageSize
	 * @param pageNum
	 * @return
	 */
	@ResponseBody
	@RequestMapping( value = "/GoodsTypeOrgan/list")
	public Pager<GoodsTypeOrgan> list(@RequestBody GoodsTypeOrgan GoodsTypeOrgan , long pageSize, long pageNum ){

		return service.paginate(GoodsTypeOrgan, pageSize, pageNum);

	}
	
	
	/**
	 * 根据ID删除GoodsTypeOrgan信息
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping( value = "/GoodsTypeOrgan/remove",method = RequestMethod.DELETE)
	public Message remove( Long id){
		
		Message msg = new Message();
		msg.setStatus(service.deleteById(id));
		return msg;
	}

	@ResponseBody
	@RequestMapping( value = "/GoodsTypeOrgan/queryAlreadyAssignedOrgans",method = RequestMethod.POST )
	public DataMessage<List<GoodsTypeOrgan>> queryAlreadyAssignedOrgans(@RequestBody GoodsTypeOrganQuery goodsTypeOrganQuery){

        List<GoodsTypeOrgan> goodsTypeOrganList = this.service.queryAlreadyAssignedOrgans(goodsTypeOrganQuery);
        return DataMessage.success(goodsTypeOrganList);
	}

}
